{
Traviesadora beta 0.2.0.13.33 (30.11.2008)
LastMod: 30.11.2008 by Prof1983

Copyright 2008, travieorama@googlemail.com

This file is part of the taviesadora project

taviesadora is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

taviesadora is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
}
unit fMovie;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, OleCtrls, AXVLC_TLB, ExtCtrls,service,chatdistributer,
  ToolWin, ImgList,MovieLibrary,RosterViewer, Buttons,Rosterdb,
  VirtualTrees;

type
  TPlayState =(psStop, psPlay, psPause);

type
  TfrmMovie = class(TForm)
    Panel3: TPanel;
    Panel1: TPanel;
    Panel2: TPanel;
    Panel4: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    tmrPositioning: TTimer;
    Splitter1: TSplitter;
    Panel5: TPanel;
    btnHide: TButton;
    StopTimer: TTimer;
    OpenDialog1: TOpenDialog;
    tbMovieSlider: TTrackBar;
    pnlWaiting: TPanel;
    ImageList1: TImageList;
    Panel7: TPanel;
    ToolBar1: TToolBar;
    TbtnPlay: TToolButton;
    TBtnPause: TToolButton;
    TBtnStop: TToolButton;
    TrvMovieLib: TTreeView;
    ImageList2: TImageList;
    Panel6: TPanel;
    ToolBar2: TToolBar;
    tbtnAdd: TToolButton;
    tbtndel: TToolButton;
    pnlInvite: TPanel;
    ToolBar3: TToolBar;
    tbtnInvite: TToolButton;
    pnlContacts: TPanel;
    Panel9: TPanel;
    ToolBar4: TToolBar;
    Label3: TLabel;
    Panel8: TPanel;
    btnInvite: TButton;
    Panel10: TPanel;
    sbtnMiniContacts: TSpeedButton;
    pnlAskAcception: TPanel;
    sbtnYes: TSpeedButton;
    sbtnNo: TSpeedButton;
    tbtnChat: TToolButton;
    ToolButton2: TToolButton;
    DockTimer: TTimer;
    trbVolume: TTrackBar;
    sbtnVolume: TSpeedButton;
    imgSpeakerMuted: TImage;
    imgSpeaker: TImage;
    Panel11: TPanel;
    procedure btnHideClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Panel1Resize(Sender: TObject);
    procedure VLCPlugin1play(Sender: TObject);
    procedure VLCPlugin1stop(Sender: TObject);
    procedure VLCPlugin1pause(Sender: TObject);
    procedure tmrPositioningTimer(Sender: TObject);
    procedure tbMovieSliderChange(Sender: TObject);
    procedure StopTimerTimer(Sender: TObject);
    procedure tbMovieSliderKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure FormCanResize(Sender: TObject; var NewWidth, NewHeight: Integer; var Resize: Boolean);
    procedure TbtnPlayClick(Sender: TObject);
    procedure TBtnStopClick(Sender: TObject);
    procedure TrvMovieLibDblClick(Sender: TObject);
    procedure TBtnPauseClick(Sender: TObject);
    procedure tbtnAddClick(Sender: TObject);
    procedure tbtndelClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure tbtnInviteClick(Sender: TObject);
    procedure lvContactsSelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
    procedure btnInviteClick(Sender: TObject);
    procedure trvContactsDblClick(Sender: TObject);
    procedure sbtnMiniContactsClick(Sender: TObject);
    procedure sbtnYesClick(Sender: TObject);
    procedure sbtnNoClick(Sender: TObject);
    procedure tbtnChatClick(Sender: TObject);
    procedure DockTimerTimer(Sender: TObject);
    procedure trbVolumeChange(Sender: TObject);
    procedure sbtnVolumeClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure trvContactsFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex);
  private
    VLCPlugin1: TVLCPlugin;
    trvContacts: TVirtualDrawTree;
  private
    chatdistri: TChatDistri;
    RosterView: TRosterViewer;
    jid: string;
    nick: string;
    OldLeft: Integer;
    OldTop: Integer;
    ChatWin: TForm;
    jidtemp: string;
    nicktemp: string;
    PlaySelAfterStop: Boolean;
    playstringForAfterStop: string;
    PartnerMode: Boolean;
    MovieLib: TMovieLib;
    PlayState: TPlayState;
    DontFireNetCMD: Boolean;
    SynchAfterAcceptance: Boolean;
    BlockMovieSliderEvent: Boolean;
    JumpToSecond: Integer;
    StopWhenTimerExec: Boolean;
    function ChangeToPartner(jid, resouce, nick: string; NetType: TNetType): TChatDistri;
    procedure SetChatDock;
  protected
    procedure DoCreate(); override;
  public
    procedure ChatDistriDestroyed();
    procedure NewInMessage(msg: string);
    procedure SetToSingleWatcher();
    procedure SetToMultipleWatcher(jid, nick: string);
    constructor Init(ChatDistri: TChatDistri; RosterDB: TRosterDB; jid, nick: string; Waiting: Boolean);
    procedure AskForAcception(jid,nick: string);
    procedure StartMovie;
    procedure PlayByAskString(AskString: string);
    procedure play;
    procedure GetPosition;
    procedure AskPosition;
    procedure pause;
    procedure stop;
    procedure PlayByFileName(FileName: string);
    procedure SetFilmPos(second: Integer);
    procedure SetChatDistributor(chat: TChatDistri);
    procedure CantFindMovie;
  end;

var
  frmMovie: TfrmMovie;

implementation

uses
  Unit1;

{$R *.dfm}

{ TfrmMovie }

procedure TfrmMovie.btnHideClick(Sender: TObject);
begin
  if (btnHide.Tag = 0) then
  begin
    Panel1.Width := btnHide.Width;
    btnHide.Caption := '>>';
    btnHide.Tag := 1;
  end
  else
  begin
    Panel1.Width := 300;
    btnHide.Caption := '<<';
    btnHide.Tag := 0;
  end;
end;

procedure TfrmMovie.SetChatDistributor(chat: TChatDistri);
begin
  ChatDistri := chat;
end;

constructor TfrmMovie.Init(ChatDistri: TChatDistri; RosterDB: TRosterDB; jid, nick: string; Waiting: Boolean);
var
  a: Integer;
  b: Integer;
  ListItem: TListItem;
  c: string;
  PartnerName: string;
begin
  SetChatDistributor(ChatDistri);
  MovieSingleWatcher.RegisterWin(self);
  BlockMovieSliderEvent := false;
  ChatWin := nil;
  PlayState := psStop;
  PlaySelAfterStop := false;
  //VLCPlugin1.Volume
  playstringForAfterStop := '';
  pnlAskAcception.Visible := false;
  trvContacts.Images := form1.imlOnlineStates;
  pnlWaiting.Visible := waiting;
  pnlWaiting.left := (Width div 2)-(pnlWaiting.Width div 2);
  pnlWaiting.top := (Height div 2)-(pnlWaiting.Height div 2);
  SynchAfterAcceptance := waiting;
  BlockMovieSliderEvent:=true;
  StopWhenTimerExec := false;
  TbtnPlay.Tag := 0;
  JumpToSecond := -1;
  DontFireNetCMD := false;
  if jid <> '' then
    SetToMultipleWatcher(jid,nick)
  else
    SetToSingleWatcher;
  MovieLib := TMovieLib.create(ExtractFilePath(Application.ExeName)+'lib.txt',TrvMovieLib);
  RosterView := TRosterViewer.Create(trvContacts, RosterDB, self, true, true, jabberObj.avatarcache);
  RosterView.On...
end;

procedure TfrmMovie.StopTimerTimer(Sender: TObject);
begin
  StopTimer.Enabled := false;
  MovieLib.CloseMovie;
  if playstringForAfterStop<>'' then
  begin
    PlayByAskString(playstringForAfterStop);
    playstringForAfterStop := '';
  end
  else if PlaySelAfterStop then
  begin
    PlayByFileName(MovieLib.PlaySelMovie);
    PlaySelAfterStop := false;
  end;

  if StopWhenTimerExec then
    close;
end;

procedure TfrmMovie.ChatDistriDestroyed;
begin
  if not StopWhenTimerExec then
  begin
    //PartnerMode := false;
    //chatdistri := nil;
    Close;
  end
  else
    chatdistri := nil;
end;

procedure TfrmMovie.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if not StopWhenTimerExec then
  begin
    Action := caNone;
    StopWhenTimerExec := True;
    VLCPlugin1.stop;
    if (chatdistri <> nil) and PartnerMode then
    begin
      ChatDistri.SendMessage('close',self);
    end;
    StopTimer.Interval := 500;
    StopTimer.Enabled := True;
  end
  else
  begin
    MovieSingleWatcher.UnRegisterWin(self);
    try
      if chatdistri<>nil then
        chatdistri.UnRegisterMsgCallback(self);
    except
      on EAccessViolation do
      begin
        //if the chatdistributor called close via destroy the chatdistr is not available anymore and causes an excetion
      end;
    end;
    RosterView.destroy;
    MovieLib.destroy;
    Action := cafree;
  end;
end;

procedure TfrmMovie.Panel1Resize(Sender: TObject);
begin
  btnHide.Left := Panel1.Width-btnHide.Width;
end;

procedure TfrmMovie.TbtnPlayClick(Sender: TObject);
begin
  VLCPlugin1.play;
end;

procedure TfrmMovie.VLCPlugin1play(Sender: TObject);
begin
  if PartnerMode then
  begin
    if not DontFireNetCMD then
    begin
      if chatdistri <> nil then
        chatdistri.SendMessage('play',self);
    end;
    DontFireNetCMD:= false;
  end;
  PlayState := psPlay;
end;

procedure TfrmMovie.TBtnStopClick(Sender: TObject);
begin
  VLCPlugin1.stop;
end;

procedure TfrmMovie.VLCPlugin1stop(Sender: TObject);
begin
  if TbtnPlay <> nil then
  begin
    if not StopWhenTimerExec then
    begin
      StopTimer.Enabled := true;
      VLCPlugin1.playlistClear;
    end;
    if PartnerMode then
    begin
      if not DontFireNetCMD then
      begin
        if (chatdistri <> nil) and not StopWhenTimerExec then
          chatdistri.SendMessage('stop',self);
      end;
      DontFireNetCMD := False;
    end;
  end;
  PlayState := psStop;
end;

procedure TfrmMovie.TBtnPauseClick(Sender: TObject);
begin
  VLCPlugin1.pause;
end;

procedure TfrmMovie.VLCPlugin1pause(Sender: TObject);
begin
  if PartnerMode then
  begin
    if not DontFireNetCMD then
    begin
        if chatdistri <> nil then
          chatdistri.SendMessage('pause',self);
    end;
    DontFireNetCMD:= false;
  end;
  PlayState := psPause;
end;

procedure TfrmMovie.StartMovie;
begin
  if PartnerMode then
  begin
    if not DontFireNetCMD then
    begin
      if chatdistri <> nil then
      begin
        chatdistri.SendMessage(MovieLib.GetAskString,self);
        chatdistri.SendMessage('play',self);
      end;
    end
    else
    begin
      DontFireNetCMD := False;
      VLCPlugin1.play;
    end;
  end
  else
  begin
    VLCPlugin1.play;
  end;
end;

procedure TfrmMovie.PlayByFileName(FileName: string);
begin
  if FileExists(FileName) then
  begin
    VLCPlugin1.addTarget(FileName, null, VLCPlayListReplace ,-666);
    StartMovie;
  end;
end;

procedure TfrmMovie.TrvMovieLibDblClick(Sender: TObject);
begin
  if (PlayState = psStop) and (MovieLib.GetPlayingID = -1) then
    PlayByFileName(MovieLib.PlaySelMovie)
  else begin
    PlaySelAfterStop := true;
    stop;
  end;
end;

procedure TfrmMovie.PlayByAskString(AskString: string);
var
  s: string;
begin
  DontFireNetCMD := true;
  s := MovieLib.OpenMovieByAskString(AskString,self);
  PlayByFileName(s);
end;

procedure TfrmMovie.tbMovieSliderChange(Sender: TObject);
begin
  if GetAsyncKeyState(VK_LBUTTON) = 0 then
  begin
    if not BlockMovieSliderEvent then
    begin
      VLCPlugin1.Position := tbMovieSlider.Position /tbMovieSlider.Max;
      if PartnerMode then
      begin
        if chatdistri <> nil then
          chatdistri.SendMessage('setposition'+sep+inttostr(VLCPlugin1.time),self);
        DontFireNetCMD:= false;
      end;
    end;
  end;
  BlockMovieSliderEvent := false;
end;

procedure TfrmMovie.tmrPositioningTimer(Sender: TObject);
begin
  if JumpToSecond > -1 then
    SetFilmPos(JumpToSecond);
  // Prof1983: 02.12.2008
  {
  if GetAsyncKeyState(VK_LBUTTON) = 0 then
  begin
    BlockMovieSliderEvent := true;
    tbMovieSlider.Position := round(VLCPlugin1.Position*tbMovieSlider.Max);
  end;
  try
    Label1.Caption := IntToStr(VLCPlugin1.Time div 60)+':'+IntToStr(VLCPlugin1.Time mod 60);
    Label2.Caption := IntToStr(VLCPlugin1.Length div 60)+':'+IntToStr(VLCPlugin1.Length mod 60);
  except
  end;
  }
  if (tbMovieSlider.Position/tbMovieSlider.Max)>(0.1) then
    BlockMovieSliderEvent := True
end;

procedure TfrmMovie.tbMovieSliderKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  VLCPlugin1.Position := tbMovieSlider.Position /tbMovieSlider.Max;
end;

procedure TfrmMovie.pause();
begin
  DontFireNetCMD := true;
  VLCPlugin1.pause;
end;

procedure TfrmMovie.play;
begin
  DontFireNetCMD := true;
  VLCPlugin1.play;
end;

procedure TfrmMovie.GetPosition;
begin
  if (chatdistri <> nil) and (PartnerMode) then
    chatdistri.SendMessage('setposition'+sep+inttostr(VLCPlugin1.time),Self );
end;

procedure TfrmMovie.stop;
begin
  DontFireNetCMD := true;
  VLCPlugin1.stop;
end;

procedure TfrmMovie.SetFilmPos(second: integer);
begin
  DontFireNetCMD := true;
  JumpToSecond := -1;
  if VLCPlugin1.Length > 0 then
    VLCPlugin1.Position := second /VLCPlugin1.Length
  else
    JumpToSecond := second;
end;

procedure TfrmMovie.AskPosition;
begin
  if (chatdistri <> nil) and (PartnerMode) then
    chatdistri.SendMessage('getposition',self);
end;

procedure TfrmMovie.CantFindMovie;
begin
  if (chatdistri <> nil) and (PartnerMode) then
    chatdistri.SendMessage('cant_find_movie',self);
end;

procedure TfrmMovie.NewInMessage(msg: string);
var
  vartext1,vartext2,s:string;
  Tokenizer:TStringTokenizer;
begin
  msg := lowercase(msg);
  vartext1 := msg;
  delete(vartext1,1,pos('=',vartext1));
  vartext2:=vartext1;
  delete(vartext1,pos(sep,vartext1),length(vartext1));
  delete(vartext2,1,pos(sep,vartext2)+1);
  delete(vartext2,pos(sep,vartext2),length(vartext2));
  if pos('file',vartext1)>0 then begin
    if PlayState = psStop then begin
      PlayByAskString(msg);
    end else begin
      playstringForAfterStop := msg;
      DontFireNetCMD := true;
      stop;
    end;
  end else if 'accepted'=vartext1 then begin
    pnlWaiting.Visible := false;
    chatdistri.SetAcceptRemote(true,self);
    if SynchAfterAcceptance then begin
      s := MovieLib.GetAskString;
      if s <> '' then begin
        chatdistri.SendMessage(s,self);
        chatdistri.SendMessage('play',self);
        if PlayState <> psStop then
          chatdistri.SendMessage('setposition'+sep+inttostr(VLCPlugin1.time),Self );
      end;
    end;
    SynchAfterAcceptance := false;
  end else if 'denied'=vartext1 then begin
    pnlWaiting.Visible := false;
    SetToSingleWatcher;
  end else if 'close'=vartext1 then begin
    SetToSingleWatcher;
  end else if 'cant_find_movie'=vartext1 then begin
    ShowMessage('your Partner hasnt got this Movie.');
    stop;
  end else if 'play'=vartext1 then begin
    play;
  end else if 'stop'=vartext1 then begin
    stop;
  end else if 'pause'=vartext1 then begin
    pause;
  end else if 'getposition'=vartext1 then begin
    GetPosition;
  end else if 'setposition'=vartext1 then begin
    try
      SetFilmPos(StrToInt(vartext2));
    except
      on EConvertError do begin
        AskPosition;
      end;
    end;
  end;
end;

procedure TfrmMovie.FormCanResize(Sender: TObject; var NewWidth,
  NewHeight: Integer; var Resize: Boolean);
begin
  //pnlWaiting.left := (NewWidth div 2)-(pnlWaiting.Width div 2);
  //pnlWaiting.top := (NewHeight div 2)-(pnlWaiting.Height div 2);
end;

procedure TfrmMovie.tbtnAddClick(Sender: TObject);
begin
  if OpenDialog1.Execute then begin
    MovieLib.AddMovie(OpenDialog1.FileName);
  end;
end;

procedure TfrmMovie.tbtndelClick(Sender: TObject);
begin
  MovieLib.DeleteSelectedMovie;
end;

procedure DecryptFile(a:string);
var
v: file of Byte;
f:integer;
C:Byte;
begin
 if lowercase(ExtractFileExt(a))<> '.cmg' then
   c := 0;
 AssignFile(v,a);
 Reset(v);
 for f := 0 to 1024 do begin
  if eof(v) then
   break;
  read(v,c);
  Seek(V,f);
  c := c xor schlssel;
  write(v,c);
 end;
 closefile(v);
end;

procedure TfrmMovie.Button1Click(Sender: TObject);
begin
 // DecryptFile('E:\Eigene Dateien\michelle\p\p\Chemistry 1 CD2.avi');
end;

procedure TfrmMovie.SetToSingleWatcher;
begin
  DockTimer.Enabled := false;
  PartnerMode := false;
  caption := '.:movies:.';
  pnlInvite.Visible := true;
  tbtnChat.Visible := false;
  MovieSingleWatcher.SetSingleWatcher(self,true);
  ChangeToPartner('','','',ntAll);
end;

procedure TfrmMovie.SetToMultipleWatcher(jid,nick:string);
begin
  MovieSingleWatcher.SetSingleWatcher(self,false);
  PartnerMode := true;
  self.jid := jid;
  Self.nick := nick;
  tbtnChat.Visible := true;
  if nick = '' then
    caption := '.:watching with '+jid+':.'
  else
    caption := '.:watching with '+nick+':.';
  pnlInvite.Visible := false;
  pnlContacts.Visible := false;
  TrvMovieLib.Color := clWindow;
end;

procedure TfrmMovie.sbtnMiniContactsClick(Sender: TObject);
begin
  tbtnInvite.Click;
end;

procedure TfrmMovie.tbtnInviteClick(Sender: TObject);
begin
  if not pnlContacts.Visible then begin
    pnlContacts.Visible := true;
    TrvMovieLib.Color := clBtnShadow;
  end else begin
    pnlContacts.Visible := false;
    TrvMovieLib.Color := clWindow;
  end;
  btnInvite.Enabled := false;
end;

procedure TfrmMovie.lvContactsSelectItem(Sender: TObject; Item: TListItem;
  Selected: Boolean);
begin
  btnInvite.Enabled := Selected;
end;

procedure TfrmMovie.btnInviteClick(Sender: TObject);
var
  ContactData:PContactData;
  NodeData:PNodeData;
  Node:PVirtualNode;
begin
  if not btnInvite.Enabled then exit;
  NODe := trvContacts.GetFirstSelected;
  NodeData := trvContacts.GetNodeData(Node);
  if NodeData = nil then exit;
  ContactData := NodeData.PContactInfo;
  if ContactData = nil then exit;
  chatdistri := ChangeToPartner(ContactData.UserId,ContactData.resource,ContactData.nick,ContactData.NetType);
  SetToMultipleWatcher(ContactData.UserId,ContactData.nick);
  SynchAfterAcceptance := true;
  chatdistri.AskForWatchingMovie(self);
  chatdistri.SetAcceptRemote(false,self);
  pnlWaiting.Visible := true;
  pnlWaiting.Left := trvContacts.Left + (trvContacts.Width div 2) - (pnlWaiting.Width div 2);
  pnlWaiting.Top :=   trvContacts.top + pnlContacts.Top + (trvContacts.height div 2) - (pnlWaiting.height div 2);
end;

procedure TfrmMovie.trvContactsDblClick(Sender: TObject);
begin
  btnInvite.Click;
end;

function TfrmMovie.ChangeToPartner(jid,resouce,nick: string;NetType:TNetType):TChatDistri;
begin
//  if jid <> Self.jid then begin
    if jid = '' then begin
      result := nil;
      PartnerMode := false;
    end else
      result := form1.StartNewChatDistri(jid,resouce,nick,NetType);
    if chatdistri <> nil then begin
      chatdistri.UnRegisterMsgCallback(self);
      chatdistri := nil;
    end;
 // end else begin
   // result := chatdistri;
 // end;
end;



procedure TfrmMovie.AskForAcception(jid, nick: string);
begin
  if not PartnerMode then begin
    if nick = '' then
      pnlAskAcception.Caption := nick+' Wants to watch a movie with you'
    else
      pnlAskAcception.Caption := jid+' Wants to watch a movie with you' ;
    pnlAskAcception.Left := trvContacts.Left + (trvContacts.Width div 2) - (pnlAskAcception.Width div 2);
    pnlAskAcception.Top :=   trvContacts.top + pnlAskAcception.Top + (trvContacts.height div 2) - (pnlAskAcception.height div 2);
    pnlAskAcception.Visible := true;
    jidtemp := jid;
    nicktemp := nick;
  end else begin
    chatdistri.MovieDenied;
  end;
end;

procedure TfrmMovie.sbtnYesClick(Sender: TObject);
var
  s:string;
begin
  pnlAskAcception.Visible := false;
  chatdistri.MovieAccepted(self);
  SetToMultipleWatcher(jidtemp,nicktemp);
  chatdistri.SetAcceptRemote(true,self);
  s := MovieLib.GetAskString;
  if s <> '' then begin
    chatdistri.SendMessage(s,self);
    chatdistri.SendMessage('play',self);
    if PlayState <> psStop then begin
      chatdistri.SendMessage('setposition'+sep+inttostr(VLCPlugin1.time),Self );
    end;
  end;
end;

procedure TfrmMovie.sbtnNoClick(Sender: TObject);
begin
  pnlAskAcception.Visible := false;
  chatdistri.MovieDenied;
end;

procedure TfrmMovie.tbtnChatClick(Sender: TObject);
begin
  if chatdistri <> nil then begin
    ChatWin := chatdistri.NewChat;
    ChatWin.Width := 170;
    ChatWin.Height := height;
    SetChatDock;
  end;

end;

procedure TfrmMovie.SetChatDock;
begin
  if chatwin <> nil then begin
    if left-ChatWin.Width <0 then begin
      left := ChatWin.Width;
      ChatWin.Left := 0;
    end else begin
      ChatWin.Left := left-ChatWin.Width;
    end;
    ChatWin.Top := top;
  end;
end;

procedure TfrmMovie.DockTimerTimer(Sender: TObject);
begin
  if  (OldLeft<>left) or (OldTop <> Top) then begin
    OldLeft := left;
    OldTop  := Top;
    SetChatDock;
  end;
end;

procedure TfrmMovie.trbVolumeChange(Sender: TObject);
begin
  if trbVolume.Position = 0 then
    sbtnVolume.Glyph := imgSpeakerMuted.Picture.Bitmap
  else
    sbtnVolume.Glyph := imgSpeaker.Picture.Bitmap;
  VLCPlugin1.Volume := trbVolume.Position;
end;

procedure TfrmMovie.sbtnVolumeClick(Sender: TObject);
begin
  if trbVolume.Position > 0 then
    trbVolume.Position := 0
  else
    trbVolume.Position := 100;
end;

procedure TfrmMovie.FormDestroy(Sender: TObject);
begin
//
end;



procedure TfrmMovie.trvContactsFocusChanged(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex);
var
  NodeData: PNodeData;
begin
  NodeData := trvContacts.GetNodeData(NOde);
  if NodeData = nil then exit;
  btnInvite.Enabled := NodeData.Level = 2;
end;

procedure TfrmMovie.DoCreate();
begin
  inherited;

  VLCPlugin1 := TVLCPlugin.Create(Self);
  VLCPlugin1.Parent := Panel3;
  VLCPlugin1.Left := 0;
  VLCPlugin1.Top := 0;
  VLCPlugin1.Width := 545;
  VLCPlugin1.Height := 646;
  VLCPlugin1.Align := alClient;
  VLCPlugin1.TabOrder := 0;
  VLCPlugin1.OnPlay := VLCPlugin1play;
  VLCPlugin1.OnPause := VLCPlugin1pause;
  VLCPlugin1.OnStop := VLCPlugin1stop;
  (*
  VLCPlugin1.ControlData = {
        07000000280043006F0075006E00740029000300090000000800000041007500
        74006F004C006F006F0070000B000000080000004100750074006F0050006C00
        610079000B00FFFF070000004200610073006500550052004C00080000000000
        0C00000045007800740065006E0074004800650069006700680074000300C442
        00000B00000045007800740065006E0074005700690064007400680003005438
        0000030000004D0052004C000800000000000900000053007400610072007400
        540069006D00650003000000000007000000560069007300690062006C006500
        0B00FFFF0600000056006F006C0075006D006500030032000000}
  *)

  trvContacts := TVirtualDrawTree.Create(Self);
  trvContacts.Parent := pnlContacts;
  trvContacts.Left := 0;
  trvContacts.Top := 17;
  trvContacts.Width := 300;
  trvContacts.Height := 135;
  trvContacts.Align := alClient;
  trvContacts.BorderStyle := bsNone;
  trvContacts.Header.AutoSizeIndex := 0;
  trvContacts.Header.Font.Charset := DEFAULT_CHARSET;
  trvContacts.Header.Font.Color := clWindowText;
  trvContacts.Header.Font.Height := -11;
  trvContacts.Header.Font.Name := 'MS Sans Serif';
  trvContacts.Header.Font.Style := [];
  trvContacts.Header.MainColumn := -1;
  trvContacts.Header.Options := [hoColumnResize, hoDrag];
  trvContacts.TabOrder := 2;
  trvContacts.OnDblClick := trvContactsDblClick;
  //trvContacts.Columns = <>
end;

end.
